<!DOCTYPE html>
<html lang="zh-cn">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        body{
            padding-bottom: 800px;
            padding-left: 30px;
        }
        .cbox{
            border: 1px solid #999;
            padding: 20px;
            margin: 10px 0px;
        }
    </style>
</head>
<body>
    <div id="app">
        <h4>根组件</h4>
        <p>基于分发的递归组件</p>
        <comp-a>
            <comp-a>
                <comp-a>
                    <comp-a></comp-a>
                </comp-a>
            </comp-a>
        </comp-a>
        <p>基于数据的递归组件</p>
        <tree-list :data="arr"></tree-list>
    </div>
    <script type="module">
        // 加载 Vue3 的ESM 模块文件
        import { createApp } from "../../assets/vue3/vue.esm-browser.js"
        const CompA = {
            name:"CompA",
            template:`
                <div class="cbox">
                    <h4>组件A</h4>
                    <slot></slot>
                </div>
            `
        }
        
        const TreeList = {
            // 提供组件自调用标签名
            name:"TreeList",
            template:`
                <ul >
                    <li v-for=" item in data ">
                        {{ item.label }}
                        <tree-list v-if="item.childern" :data="item.childern"></tree-list>
                    </li>
                </ul>
            `,
            props: {
                data: {
                    type: Array,
                    default(){
                        return []
                    }
                },
            },
        }
        createApp({
            components: {
                CompA,TreeList
            },
            data(){
                return {
                    arr:[
                        { 
                            label:"元素1",
                            childern:[
                                {
                                    label:"元素1-1",
                                    childern:[
                                        {
                                            label:"元素1-1-1",
                                        },
                                        {
                                            label:"元素1-1-2",
                                        }
                                    ] 
                                },
                                {
                                    label:"元素1-2",
                                }
                            ] 
                        },
                        { 
                            label:"元素2",
                            childern:[
                                {
                                    label:"元素2-1",
                                },
                                {
                                    label:"元素2-2",
                                    childern:[
                                            {
                                                label:"元素2-2-1",
                                            },
                                            {
                                                label:"元素2-2-2",
                                            }
                                        ] 
                                    },
                                {
                                    label:"元素2-3",
                                }
                            ] 
                        },
                        { 
                            label:"元素3"
                        }
                    ]
                }
            }
        }).mount("#app")
    </script>
</body>
</html>